package main

import (
	"fmt"
	"strconv"
)

func add(n1, n2 string) string {

	l1, l2 := len(n1)-1, len(n2)-1
	idx1, idx2 := l1, l2

	carry := uint8(0)

	res := ""
	for idx1 >= 0 || idx2 >= 0 {
		a := uint8(0)
		if idx1 >= 0 {
			a = n1[idx1] - '0'
		}

		b := uint8(0)
		if idx2 >= 0 {
			b = n2[idx2] - '0'
		}

		v := (a + b + carry) % 10
		carry = (a + b + carry) / 10
		res += strconv.Itoa(int(v))
		idx1--
		idx2--
	}

	if carry > 0 {
		res += strconv.Itoa(int(carry))
	}
	return reverseString(res)
}

func reverseString(s string) string {
	runes := []rune(s)
	for from, to := 0, len(runes)-1; from < to; from, to = from+1, to-1 {
		runes[from], runes[to] = runes[to], runes[from]
	}
	return string(runes)
}

func main() {

	n1 := "16219564149326649812121123947412857"
	n2 := "99211247412857162195641493266498121"

	fmt.Println(add(n1, n2))

}
